export default {
    namespaced:true,
    state:function(){
      return {
        user:"张三",
        age:18,
        height:177,
        weight:70,
      }
    },
    getters:{
      // 模块内getters => 不仅可以访问自身的state,getters,还可以访问根store的state,getters
      adult:function(state,getters,rootState,rootGetter){
          getters,rootState,rootGetter
          return state.age>18;
      }
    },
    mutations:{
      addAge:function(state){
          state.age++
      },
      changeName:function(state,payload){
          state.user = payload;
      }
    },
    actions:{
      // context => 和当前模块有相同属性和方法的新对象 
      // 注意: context还有rootState, rootGetters  => 获取根Store实例中的state和getters
      addAge_Async:function(context,payload){
        // var {state,getters,commit,dispatch} = context;
        return new Promise(function(resolve){
          var {commit} = context;
          setTimeout(()=>{
            commit("addAge",payload);
            resolve();
          },2000)
        })
      }
    }
  }
